package com.steel.yfmall.cloud.assistant.controller;

import com.alibaba.fastjson.JSON;
import com.steel.yfmall.cloud.assistant.api.stock.AssistantToZgServiceAPI;
import com.steel.yfmall.cloud.assistant.bean.ResponseZgMsgBean;
import com.steel.yfmall.cloud.assistant.bean.param.*;
import com.steel.yfmall.cloud.assistant.bean.param.zg.*;
import com.steel.yfmall.cloud.assistant.bean.result.APIResultAccountInfoBean;
import com.steel.yfmall.cloud.assistant.bean.result.APIResultByProductPriceBean;
import com.steel.yfmall.cloud.components.utils.base.APIListBean;
import com.steel.yfmall.cloud.components.utils.base.APIMsgBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: AssistantToZgControler
 * @Package com.steel.yfmall.cloud.assistant.controller
 * @Description: (用一句话描述该文件做什么)
 * @date 2020/12/8 14:34
 */
@RestController
@Slf4j
public class AssistantToZgController extends BaseController{

    @Resource
    private AssistantToZgServiceAPI assistantToZgServiceAPI;

    /**
     * 同步中冠价格
     *
     * @return com.steel.yfmall.cloud.assistant.biz.service.bean.ResultZgMsgBean<java.lang.Boolean>    返回类型
     * @Title: priceEffect
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param apiParaBean 参数说明
     * @author yuchaohua
     * @date 2020/12/8 14:37
     */
    @RequestMapping(value = "priceEffect")
    ResponseZgMsgBean<Boolean> priceEffect(@RequestBody APIPriceEffectBean apiParaBean) {
        if (log.isDebugEnabled()) {
            log.info("function priceEffect :" + JSON.toJSONString(apiParaBean));
        }
        return assistantToZgServiceAPI.priceEffect(apiParaBean);
    }


    /**
     * @param [apiParaBean]
     * @return com.steel.yfmall.cloud.components.utils.base.APIListBean<com.steel.yfmall.cloud.assistant.biz.service.bean.result.APIResultAccountInfoBean>    返回类型
     * @Title: 查询账户信息
     * @Description: (这里用一句话描述这个方法的作用)
     * @date 2020/12/10 14:15
     * @author lang
     * @version 1.0
     */
    @RequestMapping(value = "getAccountInfo")
    APIListBean<APIResultAccountInfoBean> getAccountInfo(@RequestBody APIParamAccountInfoBean apiParaBean) {
        if (log.isDebugEnabled()) {
            log.info("function getAccountInfo :" + JSON.toJSONString(apiParaBean));
        }
        return assistantToZgServiceAPI.getAccountInfo(apiParaBean);
    }

    /**
     * 同步企业收货地址给中冠
     *
     * @return com.steel.yfmall.cloud.components.utils.base.APIMsgBean<java.lang.Boolean>    返回类型
     * @Title: templateCompanyAddress
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param apiParaBean 参数说明
     * @author yuchaohua
     * @date 2020/12/10 22:54
     */
    @RequestMapping(value = "templateCompanyAddress")
    APIMsgBean<Boolean> templateCompanyAddress(@RequestBody APIParamCompanyAddressBean apiParaBean) {
        if (log.isDebugEnabled()) {
            log.info("function templateCompanyAddress :" + JSON.toJSONString(apiParaBean));
        }
        return assistantToZgServiceAPI.templateCompanyAddress(apiParaBean);
    }

    /**
     * 结算后抛送订单与装车单
     *
     * @param apiParaBean 订单号	orderNo
     *                    装车单号	invoiceNo
     */
    @RequestMapping(value = "doOrderSettlementInfo")
    public void doOrderSettlementInfo(@RequestBody List<APIParamOrderAndInvoiceBean> apiParaBean) {
        if (log.isDebugEnabled()) {
            log.info("function doOrderSettlementInfo :" + JSON.toJSONString(apiParaBean));
        }
        assistantToZgServiceAPI.doOrderSettlementInfo(apiParaBean);
    }

    /**
     * 开立发票后向电商反馈
     *
     * @param zgOrderParamBean 订单号		orderNo
     *                         电商号		draftNo
     *                         申请开票单号	avNo
     * @return
     */
    @RequestMapping(value = "invoiceResult")
    public ResponseZgMsgBean<?> invoiceResult(@RequestBody APIParamInvoiceResultBean apiParaBean) {
        if (log.isDebugEnabled()) {
            log.info("function invoiceResult :" + JSON.toJSONString(apiParaBean));
        }
        return assistantToZgServiceAPI.invoiceResult(apiParaBean);
    }

    /**
     * 在订单建立之后中冠会通知电商，订单状态变更信息通知。
     *
     * @param apiParamAccountInfoBean
     * @return
     */
    @RequestMapping(value = "productionStatusChange")
    public ResponseZgMsgBean<String> productionStatusChange(@RequestBody APIParamProductionStatusChangeBean apiParaBean) {
        if (log.isDebugEnabled()) {
            log.info("function productionStatusChange :" + JSON.toJSONString(apiParaBean));
        }
        return assistantToZgServiceAPI.productionStatusChange(apiParaBean);
    }

    /**
     * 产销框架合同变动时，通知电商，这里修改电商的框架合同状态
     *
     * @param apiZgSO06Bean
     * @return 结果
     * @author jia chang bao
     */
    @RequestMapping(value = "updateFrameworkContractInfo")
    public ResponseZgMsgBean<String> updateFrameworkContractInfo(@RequestBody APIZgSO06Bean apiZgSO06Bean) {
        log.debug("产销框架合同发生变化："+apiZgSO06Bean.toString());
        return assistantToZgServiceAPI.updateFrameworkContractInfo(apiZgSO06Bean);
    }

    /**
     * 根据 订单号 和 客户编号 查询结算单信息
     *
     * @param apiParamOrderSettlementBean
     * @return 结果
     * @author jia chang bao
     */
    @RequestMapping(value = "getOrderSettlement")
    public APIListBean<APIParamOrderSettlementBean> getOrderSettlement(@RequestBody APIParamOrderSettlementBean apiParamOrderSettlementBean) {
        return assistantToZgServiceAPI.getOrderSettlement(apiParamOrderSettlementBean);
    }

    /**
     * 中冠订单变更
     * @Title: productionOrderChange
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param apiParaBean 参数说明
     * @return com.steel.yfmall.cloud.assistant.bean.ResponseZgMsgBean<java.lang.String>    返回类型
     * @author yuchaohua
     * @date 2021/1/15 11:55
     */
    @RequestMapping(value = "productionOrderChange")
    public ResponseZgMsgBean<String> productionOrderChange(@RequestBody APIZgChangerOrderBean apiParaBean){
        ResponseZgMsgBean<String> stringResponseZgMsgBean = new ResponseZgMsgBean<>();
        if (log.isDebugEnabled()){
            log.info("产销订单变更，function productionOrderChange: " + JSON.toJSONString(apiParaBean));
        }
        try {
            stringResponseZgMsgBean = assistantToZgServiceAPI.productionOrderChange(apiParaBean);
        }catch (Exception e){
            log.error("function productionOrderChange：" , e);
        }
        return stringResponseZgMsgBean;
    }

    /**
     * 查询副产品价格
     * @Title: getByProductPriceBeanByPara
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param apiParaBean 参数说明
     * @return com.steel.yfmall.cloud.components.utils.base.APIMsgBean<com.steel.yfmall.cloud.assistant.bean.result.APIResultByProductPriceBean>    返回类型
     * @author yuchaohua
     * @date 2021/2/23 12:28
     */
    @RequestMapping(value = "getByProductPriceBeanByPara")
    APIMsgBean<APIResultByProductPriceBean> getByProductPriceBeanByPara(@RequestBody APIParamByProductPriceBean apiParaBean){
        if (log.isDebugEnabled()){
            log.info("查询副产品价格，function getByProductPriceBeanByPara: " + JSON.toJSONString(apiParaBean));
        }
        return assistantToZgServiceAPI.getByProductPriceBeanByPara(apiParaBean);
    }

    /**
     * 接收中冠终到地点数据
     * @param apiParamEndCodeBean
     * @return 结果
     * @author jia chang bao
     */
    @RequestMapping(value = "receiveZgEndCode")
    public APIMsgBean<Boolean> receiveZgEndCode(@RequestBody APIParamEndCodeBean apiParamEndCodeBean) {
        return assistantToZgServiceAPI.receiveZgEndCode(apiParamEndCodeBean);
    }

}
